<template>
	<view class="content">
		<button class="size" v-for="(site,key) in list" @tap="addEventListener(key)">{{site}}</button>
		<view>{{info}}</view>
		<button class="size" @tap="quit">退出应用</button>
		<button class="size" @tap="restart">重启当前的应用</button>
		<button class="size" @tap="openURL">调用第三方程序打开指定的URL</button>
		<button class="size" @tap="launchApplication">调用第三方程序</button>
		<button class="size" @tap="checkApp">判断第三方程序是否已存在</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {
					"appid": "当前应用的APPID",
					"arguments": "第三方程序调用时传递给程序的参数",
					"channel": "应用的渠道标识",
					'launcher': "应用启动来源",
					"origin": "应用安装来源",
					"version": "客户端的版本名称",
					"versionCode": "客户端的版本号",
					"innerVersion": "客户端5+运行环境的内部版本号",
					"uniVersion": "客户端uni-app运行环境的版本号",
					"launchLoadedTime": "获取当前应用首页加载的时间",
					"processId": '获取当前应用的进程标识',
					"startupTime": " 获取当前应用的启动时间戳",
					"isRecovery": "应用是否由于内核崩溃自动恢复",
				},
				info: null
			}
		},
		onLoad() {

		},
		methods: {
			addEventListener(key) {
				this.info = plus.runtime[key];
			},
			quit() {
				plus.runtime.quit();
			},
			restart() {
				plus.runtime.restart();
			},
			openURL() {
				const url = "sinaweibo://gotohome"
				plus.runtime.openURL(url, function(err) {
					console.log("err=>", err)
				});
			},
			launchApplication() {
				if (plus.os.name == "Android") {
					plus.runtime.launchApplication({
						pname: "com.android.browser",
						extra: {
							url: "http://www.html5plus.org"
						}
					}, function(e) {
						console.log("Open system default browser failed: " + e.message);
					});
				} else if (plus.os.name == "iOS") {
					plus.runtime.launchApplication({
						action: "http://www.html5plus.org"
					}, function(e) {
						console.log("Open system default browser failed: " + e.message);
					});
				}
			},
			checkApp() {
				if (plus.runtime.isApplicationExist({
						pname: 'com.tencent.mm',
						action: 'weixin://'
					})) {
					console.log("微信应用已安装");
				} else {
					console.log("微信应用未安装");
				}

			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
